trigger UniqueTemplateName on Template__c (before insert) {
    if(Trigger.isBefore)
    {
        if(Trigger.isInsert){
           for(Template__c t: Trigger.new){
              for(Template__c temp: [Select Name from Template__c b where b.Name = :t.Name])
              {
                  t.addError('The Template with this name already exists.');          
              }
           }
       }
    }
}